﻿Public Class ComputeDepreciationClass
    Public Shared Function ComputeDepreciation(depreciationYears As Integer,
                                                disposedDate As Date,
                                                assetAmount As Decimal,
                                                dateAcquired As Date,
                                                depreciationType As Integer) As Decimal
        Dim result As Decimal = 0
        If depreciationType = Nothing Then
            depreciationType = 0
        End If
        If dateAcquired = Nothing Then
            depreciationType = 0
        End If
        Select Case depreciationType
            Case 1 'straight line
                result = If(Not dateAcquired = Nothing, _
                            If(depreciationYears > 0 _
                               , ((assetAmount / depreciationYears) / 12) * DateDiff(DateInterval.Month, CDate(dateAcquired), CDate(If(Not disposedDate = Nothing _
                                                                                                                                       , disposedDate _
                                                                                                                                       , Now) _
                                                                                                                                   ) _
                                                                                                                               ) _
                                                                                                                           , 0) _
                                                                                                                       , 0)
            Case Else 'straight line
                result = 0
        End Select
        Return result
    End Function
End Class
